import React, { Component } from 'react'
import { Form, Select, Input } from 'antd'
import PropTypes from 'prop-types'
const Option = Select.Option


export default  class AddForm extends Component {
	static propTypes = {
		categorys: PropTypes.array.isRequired,
		parentId: PropTypes.string.isRequired,
	}
	render() {
		const { categorys, parentId } = this.props
		return (
			<div>
				<Form
					name='addCategory'
					layout='vertical'
					ref={this.props.formRef}
					initialValues={{
						parentId: parentId,
					}}
				>
					<Form.Item
						name='parentId'
						label='所属分类'
						rules={[{ required: true, message: '请选择所属分类' }]}
					>
						<Select>
							<Option value='0'>一级分类</Option>
							{categorys.map((c) => {
								return (
									<Option key={c._id} value={c._id}>
										{c.name}
									</Option>
								)
							})}
						</Select>
					</Form.Item>
					<Form.Item
						name='categoryName'
						label='品类名称'
						rules={[
							{ required: true, message: '请输入分类名称' },
							{ max: 10, message: '不能超过十个字' },
						]}
					>
						<Input placeholder='请输入分类名称' />
					</Form.Item>
				</Form>
			</div>
		)
	}
}
